import datetime


class CountRecord(object):
    def __init__(self):
        self.countList = [['ID' ,'类别' ,'账户' ,'金额' ,'时间' ,'说明']]
        self.admins = {'admin':'123456'}
        self.users = {'list':'123456'}

    def mainRun(self):
        power = 0
        for i in range(1 ,4):
            user = input('请输入你的账号：')
            password = input('请输入你的密码：')
            result = self.login(user, password)
            if result == 0:
                print('账号或密码错误请重新输入，你还有' + str(3 - i) + '次机会')
                if i == 3:
                    print('登录失败')
                    return 0;
            elif result == 1:
                print('用户登录成功')
                self.userMenu()
                power = 1
                break
            else:
                print('管理员登录成功')
                self.adminMenu()
                power = 2
                break
        while True:
            chiose = input('请输入你想执行的操作')
            if (chiose == '1' and power == 1) or (chiose == '4' and power == 2):
                self.printAount()
            elif chiose == '2' and power ==1:
                self.printById()
            elif chiose == '1' and power == 2:
                self.addAount()
            elif chiose == '2' and power == 2:
                self.updateBuId()

    def deleteCountById(self ,id = None):
        if id == None:
            id = int(input('请输入你想要进行的操作的id'))
        try:
            del self.countList[id]
        except Exception as e:
            print('删除失败，请查看具体问题：' ,e)
        else:
            index = 0
            for count in self.countList:
                if index != 0:
                    count[0] = index
                index = index+1


    def login(self ,user ,password):
        for k,v in self.users.items():
            if user == k:
                if password == v:
                    return 1
                else:
                    break
        for k,v in self.admins.items():
            if user == k:
                if v ==password:
                    return 2
                else:
                    break
        return 0


    def userMenu(self):
        print("1.查询所有  2.按条件查询")

    def adminMenu(self):
        print("1.添加财务 2.编辑财务 3.删除财务 4.查询财务 5.退出系统")

    def printAount(self):
        for count in self.countList:
            for value in count:
                print(str(value) + '              ' ,end='')
            print()

    def printById(self ,id = None):
        if id == None:
            id = int(input('请输入你想查询的id'))
        for value in self.countList[0]:
            print(str(value) + '                            ', end='')
        print()
        for value in self.countList[id]:
            print(str(value) + '                           ', end='')
        print()

    def updateBuId(self):
        id = int(input('请输入你想修改的id'))
        self.printById(id)
        print('1.ID 2.类别 3.账户 4.金额 5.时间 6.说明')
        index= int(input('请输入你想要修改的词条'))
        value = input('请输入你想要更改的内容')
        self.countList[id][index - 1] = value




    def addAount(self):
        list = []
        id = len(self.countList)
        list.append(id)
        aClass = input('请输入类别')
        list.append(aClass)
        aount = input('请输入账户')
        list.append(aount)
        money = input('请输入金额')
        list.append(money)
        time = datetime.datetime.now().date()
        list.append(time)
        notice = input('请输入说明')
        list.append(notice)
        self.countList.append(list)

cR = CountRecord()
cR.mainRun()
